package com.asframe.astruts2.config
{
	import com.asframe.astruts2.beans.AstrutsBeans;
	import com.asframe.astruts2.beans.LoadingBean;
	import com.asframe.astruts2.beans.MediatorBean;
	import com.asframe.astruts2.beans.ViewBean;
	
	import flexunit.framework.Assert;
	
	import org.flexunit.asserts.assertEquals;
	import org.flexunit.asserts.assertTrue;
	
	public class ConfigParseTest
	{		
		[Before]
		public function setUp():void
		{
		}
		
		[After]
		public function tearDown():void
		{
		}
		
		[BeforeClass]
		public static function setUpBeforeClass():void
		{
		}
		
		[AfterClass]
		public static function tearDownAfterClass():void
		{
		}
		
		[Test]
		public function testConfigParse():void
		{
			var xml:XML = 
				<astruts>
					<!-- Astruts2系统的一些设置 -->
					<systems>
						<!-- 是否遵循Astruts2的相关与约定 -->
						<convention>true</convention>
						<!-- 是否开启View的元数据标签检测 -->
						<viewMetadata>true</viewMetadata>
						<!-- 是否开启中介的元数据标签检测 -->
						<mediatorMetadata>true</mediatorMetadata>
						<!-- View的默认参数设置 -->
						<viewSetup swap="false" visible="true" source="root"  lazy="true" undoSite="false"
							loading="windowLoading" initEvent="addedToStage" autoInit="true" drag="false" parent="root"/>
					</systems>
					
					<!-- 变量，可以在应用以及在配置文件中使用 -->
					<vars>
						<var name="name" value="soda" />
						<var name="package" value="com.asframe.astruts2.test" />
						<var name="age" value="18" type="int" />
					</vars>
				
					<properties>
						<file>properties.properties</file>
					</properties>
					
					<!-- 通知拦截配置 -->
					<noticeFilters>
						<!-- 通知的拦截接口 -->
						<noticeHold clazz="">
							<!-- 需要拦截的事件，支持通配符 -->
							<notices>name,open*,*cmd</notices>
						</noticeHold>
						<noticeHold clazz="">
							<notices>name,open*,*cmd</notices>
						</noticeHold>
					</noticeFilters>
					
					<!-- loading配置 ,有点类似ViewMapping -->
					<loadings>
						<loading name="bigLoading" path="${package}.WindowLoadView" lazy="true">
							<res>soda/test</res>
						</loading>
						<loading name="teamLoading" path="com.mingyoo.tribe.ui.TeamLoadingView" lazy="false">
							<res>soda/test</res>
						</loading>
					</loadings>
					
					<!-- UI和中介的配置 -->
					<views>
						<view name="login" clazz="Login">
							<res></res>
							<mediator name="" view="">
								<notices></notices>
							</mediator>
							<mediator name="" view=""/>
						</view>
					</views>
					
					<!-- 指令的配置 -->
					<cmds>
						<cmd name="LoadPlayerCmd" singlet="true" soon="true" 
													clazz="com.mingyoo.tribe.roles.cmd.LoadPlayerCmd" >
							<interests>loginSuccess</interests>
						</cmd>
					</cmds>
					
					<modules>
						<module name="" clazz="" >
							<notices></notices>
						</module>
					</modules>
					
					<beans>
						<bean name="session" clazz="con.Session" factory="getInstance" />
					</beans>
				</astruts>
				
			var configParse:ConfigParse = new ConfigParse();
			var astrutsBean:AstrutsBeans = configParse.configParse(xml);
			
			//默认设置
			var viewSetupBean:ViewBean = astrutsBean.viewSetup;
			assertTrue(viewSetupBean != null);
			assertEquals(viewSetupBean.swap,false);
			assertEquals(viewSetupBean.visible,true);
			assertEquals(viewSetupBean.singleton,true);
			assertEquals(viewSetupBean.source,"root");
			assertEquals(viewSetupBean.initEvent,"addedToStage");
			
			var loadingBean:LoadingBean = astrutsBean.loadings[0];
			
			assertEquals(loadingBean.name,"bigLoading");
			assertEquals(loadingBean.clazz,"com.mingyoo.tribe.ui.WindowLoadView");
			assertEquals(loadingBean.res,"soda/test");
			
			var viewBean:ViewBean = astrutsBean.views[0];
			assertEquals(viewBean.singleton,false);
			assertEquals(viewBean.visible,true);
			assertEquals(viewBean.drag,true);
			assertEquals(viewBean.name,"loginView");
			assertEquals(viewBean.clazz,"com.asframe.astruts2.test.Login");
			assertEquals(viewBean.reses[0],"res/ui/login.swf");
			assertEquals(viewBean.reses[1],"res/ui/com.swf");
			
			var mediatorBean:MediatorBean = viewBean.mediators[0];
			assertEquals(viewBean.name,"loginView");
			assertEquals(viewBean.clazz,"com.asframe.astruts2.test.Login");
			assertEquals(viewBean.clazz,"com.asframe.astruts2.test.Login");
			
			viewBean = astrutsBean.views[1];
			assertEquals(viewBean.singleton,false);
			assertEquals(viewBean.visible,true);
			assertEquals(viewBean.drag,true);
			assertEquals(viewBean.name,"login");
			assertEquals(viewBean.clazz,"com.asframe.astruts2.test.Login");
			assertEquals(viewBean.reses[0],"res/ui/login.swf");
			assertEquals(viewBean.reses[1],"res/ui/com.swf");
			
		}
	}
}